﻿using LJX.SmartPark.Common.Extensions;
using LJX.SmartPark.Common.ResponseOutput;
using LJX.SmartPark.Domain.SafeManage.PatrolPerson;
using LJX.SmartPark.Domain.SafeManage.PatrolRecord;
using LJX.SmartPark.Domain.SafeManage.plan;
using LJX.SmartPark.Service.Repository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static LJX.SmartPark.Service.SafeManage.PatrolRecordServeice;

namespace LJX.SmartPark.Service.SafeManage
{
    public class PatrolplanServeice: IPatrolplanServeice
    {
        private readonly IRepository<Patrolplan> _patrolplanService;

        public PatrolplanServeice(IRepository<Patrolplan> patrolplanService)
        {
            _patrolplanService = patrolplanService;
        }

        /// <summary>
        /// 获取总条数
        /// </summary>
        /// <returns></returns>
        public int GetCount()
        {
            return _patrolplanService.GetCount();
        }

        /// <summary>
        /// 显示分页
        /// </summary>
        /// <param name="fyPlan"></param>
        /// <returns></returns>
        public async Task<Response<List<Patrolplan>>> GetPatrolplanAsync(FyPlan fyPlan)
        {
            var students = await _patrolplanService.GetAllListAsync();
            var result = students.MapToList<Patrolplan>();

            var totalCount = result.Count();
            result = result.Skip(((fyPlan.pageIndex - 1) * fyPlan.pageSize)).Take(fyPlan.pageSize).ToList();
            return Response<List<Patrolplan>>.Ok(result, totalCount);
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public Response<Patrolplan> GetPatrolplanById(Patrolplan input)
        {
            var patrolRecord = _patrolplanService.GetListQuery().FirstOrDefault(m => m.Id == input.Id);
            var result = patrolRecord.MapTo<Patrolplan>();
            return Response<Patrolplan>.Ok(result);
        }

        /// <summary>
        /// 查询分页
        /// </summary>
        public class FyPlan
        {
            public int pageIndex { get; set; }
            public int pageSize { get; set; }
        }
    }
}
